HOME_DIR="/home/steam"
DST_DIR="${HOME_DIR}/dst"
BIN_PATH="${DST_DIR}/bin/dontstarve_dedicated_server_nullrenderer"
ARGS=("-persistent_storage_root" "${HOME_DIR}" "-conf_dir" "save")
MODS_DIR="${HOME_DIR}/mods"

cd $(dirname "$BIN_PATH")

if [[ -e "${MODS_DIR}" ]]; then
    cp -r "${MODS_DIR}" "${DST_DIR}"
fi

# Check for updates
"$HOME_DIR/steamcmd/steamcmd.sh" +login anonymous +force_install_dir "$HOME_DIR/dst" +app_update 343050 validate +quit

# Run
tail -f "/var/run/dstcommand" | "$BIN_PATH" "${ARGS[@]}" "$@"
